'''
Author: FusionYu
Description: 
LastEditors: FusionYu
LastEditTime: 2023-03-06 12:27:18
'''
import cv2
import numpy as np

width = 1280
height = 720

image_path = "/home/rhq/xiangmu/1677490785_761923_0003.png"
img = cv2.imread(image_path)
img = cv2.resize(img, (width, height))
mask = np.zeros((height, width, 3))

d = 5
flag = False


def CircleCallback(event, x, y, flags, param):
    global flag, d
    if event == cv2.EVENT_LBUTTONDOWN:
        if flag:
            cv2.imwrite("mask.png", mask)
        flag = (not flag)
    if flag:
        cv2.circle(mask, (x, y), d, 255, 2 * d)

    if event == cv2.EVENT_RBUTTONDOWN:
        d = 30 - d


video_name = "frame"
cv2.namedWindow(video_name)
cv2.setMouseCallback(video_name, CircleCallback)

while True:

    frame = np.float32(img)
    img = img + mask * 0.1
    frame = frame / 255
    cv2.imshow(video_name, frame)

    if cv2.waitKey(10) & 0xff == 27:
        break

# cv2.imwrite("/home/rhq/xiangmu/mask.png", img)
